/*************************************************************************
> File Name: 4.c
> Author: hzy
> Created Time: 2023-07-24 17:05:02
> Description: 4、将数组中前n个数按反序存放。（指针）
************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define N 10

int main(int argc, char const *argv[])
{
    int arr[N] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
    int *p = arr;
    int n = 0;
    printf("请输入需要将前n位反序存放：");
    scanf("%d", &n);

    for (int i = 0; i < (n / 2); i++)
    {
        int temp = *(p + i);
        *(p + i) = *(p + n - 1 - i);
        *(p + n - 1 - i) = temp;
    }

    printf("交换后的结果为：");
    for (int j = 0; j < N; j++)
    {
        printf("%d", *(p + j));
    }
    printf("\n");

    return 0;
}